package com.nexgo.payment.trans.scanpreauthvoid;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.nexgo.payment.R;
import com.nexgo.payment.action.inputadminpwd.AdminPasswordFragment;
import com.nexgo.payment.action.scan.ScanFragment;
import com.nexgo.payment.databases.Repository;
import com.nexgo.payment.trans.AbsTransActivity;
import com.nexgo.payment.util.ActivityUtils;

/**
 * 扫码预授权撤销
 * Created by 谢豪景 on 2017/11/3.
 */
public class ScanPreAuthVoidActivity extends AbsTransActivity<ScanPreAuthVoidContract.Presenter> implements ScanPreAuthVoidContract.View{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new ScanPreAuthVoidPresenter(this, Repository.getInstance());
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.start();
    }

    @Override
    public void showInputAdminPassword() {
        AdminPasswordFragment adminPwdFragment = AdminPasswordFragment.newInstance();
        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.contentFrame);
        if (fragment == null) {
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), adminPwdFragment, R.id.contentFrame);
        } else {
            ActivityUtils.replaceFragmentToActivity(getSupportFragmentManager(), adminPwdFragment, R.id.contentFrame);
        }
    }

    @Override
    public void showScanFragment() {
        ScanFragment scanFragment = ScanFragment.newInstance();
        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.contentFrame);
        if (fragment == null) {
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), scanFragment, R.id.contentFrame);
        } else {
            ActivityUtils.replaceFragmentToActivity(getSupportFragmentManager(), scanFragment, R.id.contentFrame);
        }
    }
    public static Intent newInstance(Context context) {
        return new Intent(context, ScanPreAuthVoidActivity.class);
    }

}
